package org.dant.ant.extension.net.processors;

import org.dant.ant.extension.net.DefaultDispatcher;
import org.dant.ant.extension.net.repository.ProcessGroup;
import org.dant.ant.extension.net.repository.ProcessItem;
import org.dant.ant.extension.tasks.internal.RemoteResponse;

public class Executable {

  public void shutdown(String processKey, RemoteResponse response) {
    ProcessGroup group = DefaultDispatcher.getProcessRepository().getProcessGroup(processKey);
    if (group == null) {
      response.setSuccess(false);
      response.setResult("No process group [" + processKey + "] exist in the repository");
      return;
    }
    ProcessItem process = group.getLast();
    if (process == null) {
      response.setSuccess(false);
      response.setResult("No process exist in the group [" + processKey + "]");
      return;
    }
    group.remove(process);
    response.setResult("One process removed from the group [" + processKey + "] in the repository");
  }
}
